// pages/me/me.js
var app = getApp();
Page({
  data: {
    userInfo:null,
    album_list: [],  //相册总容器
    arr_left: [],    //相册左右容器
    arr_right: [],
    pnow: 1,     //当前页
    pcount: 0,   //分页总数
    album_count:0,  //用户的相册总数
    album_collect_count:0, //用户相册总收藏数
    album_flower_count:0, //用户相册总赞数
    default_src:'',
  },

  //设置相册封面失效时重置为默认封面
  Load_Err(e){
    var index = e.currentTarget.dataset.index;
    var side = e.currentTarget.dataset.side;
    var t = this
    app.SetDefaltCover(e, t);
  },




  //重置相册数据
  ResetData(t){
    t.setData({
      album_list: [],  //相册总容器
      arr_left: [],    //相册左右容器
      arr_right: [],
      pnow: 1,     //当前页
      pcount: 0,   //分页总数
    })
  },

  /**
   * 跳转到发布页面
   */
  Jump_Issue(e){
    var album_id = e.currentTarget.dataset.album_id;
    var album_name = e.currentTarget.dataset.album_name;
    var album_pic_cover = e.currentTarget.dataset.album_pic_cover;

    
    if(album_id == 'issue'){
      var url = '../issue/issue?album_id=' + album_id;
    }else{
      var url='../issue/issue?album_id=' + album_id + "&album_name=" + album_name + "&album_pic_cover=" + album_pic_cover;
    }
    wx.navigateTo({
      url:url
    })
  },




  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      default_src:app.globalData.default_img
    })
    var t = this;
    //获取用户信息
    app.getUserInfo(function(res){
      t.setData({
        userInfo:res
      })
     // t.GetAllAlbums(t);
    });
  },




  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var t = this;
    if (wx.getStorageSync('change')){
      t.setData({
        album_list: [],  //相册总容器
        arr_left: [],    //相册左右容器
        arr_right: [],
        pnow: 1,     //当前页
        pcount: 0,   //分页总数
      })
    }
    t.ResetData(t)
    t.GetAllAlbums(t);
    t.GetUserFlowerCount(t);
    t.GetUserCollectCount(t);
    t.GetUserAlbumCount(t);
    return;

  },


  //获取用户相册总数 

  GetUserAlbumCount(t) {
    app.getOpenid(function (openid) {
      app.VC(function (vc) {
        wx.request({
          url: app.globalData.urls,
          data: {
            GetTypes: 'Get_User_Album_Count',
            openid: openid,
            vc:vc
          },
          success(res) {
            t.setData({
              album_count: res.data
            })
          }
        })
      })
    })
  },


  //获取用户相册被赞总数
  GetUserFlowerCount(t){
    app.getOpenid(function (openid) {
      app.VC(function (vc) {
        wx.request({
          url: app.globalData.urls,
          data: {
            GetTypes: 'Get_User_All_Album_Flower_Count',
            openid: openid,
            vc:vc
          },
          success(res) {
            t.setData({
              album_flower_count:res.data
            })
          }
        })
      })
    })
  },




  //获取用户相册被收藏总数
  GetUserCollectCount(t) {
    app.getOpenid(function (openid) {
      app.VC(function (vc) {
        wx.request({
          url: app.globalData.urls,
          data: {
            GetTypes: 'Get_Album_All_Collect_Count',
            openid: openid,
            vc:vc
          },
          success(res) {
            t.setData({
              album_collect_count: res.data
            })
          }
        })
      })
    })
  },



  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var t = this;
    app.getOpenid(function (openid) {
      app.GetAllAlbum(t, openid, '', function () {})
    })
  },




  //获取用户所有相册
  GetAllAlbums(t){
    app.getOpenid(function (openid) {
      app.GetAllAlbum(t, openid,'', function(){

      })
    })
  },
  
  

  //相册的删除
  Album_Del(e){
    var t = this;
    var aid = e.target.dataset.aid;
    wx.showModal({
      //title: '提示',
      content: '确认删除该相册',
      success: function (res) {
        if (res.confirm) {
          app.getOpenid(function (oid) {
            app.VC(function(vc){
              wx.request({
                url: app.globalData.urls,
                data: {
                  GetTypes: 'Album_Dels',
                  oid: oid,
                  aid: aid,
                  vc:vc
                },
                success: function (res) {
                  wx.setStorageSync('change', true)    //标记修改状态，以便主页更新数据
                  t.ResetData(t)
                  t.GetAllAlbums(t)
                  //t.GetAllAlbums(t);
                  t.GetUserFlowerCount(t);
                  t.GetUserCollectCount(t);
                  t.GetUserAlbumCount(t);
                }
              })
            });
          })
        }
      }
    })
  },





})